package com.cxh.mchat.user.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.cxh.mchat.common.security.bean.LoginUser;
import com.cxh.mchat.user.bean.UserLoginReqBean;
import com.cxh.mchat.user.bean.UserRegisterReqBean;
import com.cxh.mchat.user.entity.User;
import com.cxh.mchat.user.service.IUserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author cxh
 * @date 2021/12/27 16:55
 **/
@RestController
public class AuthController {
    @Resource
    private IUserService userService;

    @PostMapping("/register")
    public R<User> register(@Validated @RequestBody UserRegisterReqBean reqBean){
        return R.ok(userService.register(reqBean));
    }

    @PostMapping("/login")
    public R<LoginUser> login(@Validated @RequestBody UserLoginReqBean reqBean){
        return R.ok(userService.login(reqBean));
    }
}
